package utils

import (
	"fmt"
	"github.com/google/uuid"
	_ "github.com/google/uuid"
	"math/rand"
	"strings"
)

// GetRandName 随机生成不同长度的用户名 num isZh 是否是中文
func GetRandName(num int, isZh bool) string {
	if num < 1 {
		return ""
	}
	var str string
	if isZh {
		str = "一乙二十丁厂七卜人入八九几儿了力乃刀又三于干亏士工土才寸下大丈与万上小口巾山千乞川亿个勺久凡及夕丸么广亡门义之尸弓己已子卫也女" +
			"飞刃习叉马乡丰王井开夫天无元专云扎艺木五支厅不太犬区历尤友匹车巨牙屯比互切瓦止少日中冈贝内水见午牛手毛气升长仁什片仆化仇币仍仅" +
			"斤爪反介父从今凶分乏公仓月氏勿欠风丹匀乌凤勾文六方火为斗忆订计户认心尺引丑巴孔队办以允予劝双书幻玉刊示末未击打巧正扑扒功扔去甘" +
			"世古节本术可丙左厉右石布龙平灭轧东卡北占业旧帅归且旦目叶甲申叮电号田由史只央兄叼叫另叨叹四生失禾丘付仗代仙们仪白仔他斥瓜乎丛令" +
			"用甩印乐句匆册犯外处冬鸟务包饥主市立闪兰半汁汇头汉宁穴它讨写让礼训必议讯记永司尼民出辽奶奴加召皮边发孕圣对台矛纠母幼丝式刑动扛" +
			"寺吉扣考托老执巩圾扩扫地扬场耳共芒亚芝朽朴机权过臣再协西压厌在有百存而页匠夸夺灰达列死成夹轨邪划迈毕至此贞师尘尖劣光当早吐吓虫" +
			"曲团同吊吃因吸吗屿帆岁回岂刚则肉网年朱先丢舌竹迁乔伟传乒乓休伍伏优伐延件任伤价份华仰仿伙伪自血向似后行舟全会杀合兆企众爷伞创肌" +
			"朵杂危旬旨负各名多争色壮冲冰庄庆亦刘齐交次衣产决充妄闭问闯羊并关米灯州汗污江池汤忙兴宇守宅字安讲军许论农讽设访寻那迅尽导异孙阵" +
			"阳收阶阴防奸如妇好她妈戏羽观欢买红纤级约纪驰巡寿弄麦形进戒吞远违运扶抚坛技坏扰拒找批扯址走抄"
	} else {
		str = "1234567890qwertyuiopasdfghjklzxcvbnm"
	}
	rt := []rune(str)
	getName := ""
	for i := 0; i < num; i++ {
		getName = getName + string(rt[rand.Intn(len(rt)-1)])
	}
	return getName
}

// GetRandNum 随机数
func GetRandNum(start int, end int) int {
	return rand.Intn(end) + start
}

// GetRandFamilyName 随机获取姓氏
func GetRandFamilyName() string {
	oneWord := `赵钱孙李周吴郑王冯陈褚卫蒋沈韩杨朱秦尤许何吕施张孔曹严华金魏陶姜戚谢邹喻柏水窦章云苏潘葛奚范彭郎鲁韦昌马苗凤花方俞任袁柳邓鲍` +
		`史唐费廉岑薛雷贺倪汤藤殷罗毕郝邬安常乐于时付皮卞齐康伍余元卜顾孟平黄和穆肖尹姚邵湛汪祁毛禹狄米贝明藏计伏成戴谈宋茅庞` +
		`熊纪舒屈项祝董梁杜阮蓝闵席季麻强贾路娄危江童颜郭梅盛林刁钟徐邱骆高夏蔡田樊胡凌霍虞万支柯昝管卢莫经房裘缪干解应宗丁宣贲邓郁单杭洪` +
		`包诸左石崔吉钮龚程嵇邢滑裴陆荣翁荀羊于惠甄曲家封芮羿储靳汲邴糜松井段富巫乌焦巴弓牧隗山谷车侯宓蓬全郗班仰秋仲伊宫宁仇栾暴甘钭厉戎` +
		`祖武符刘景詹束龙叶幸司韶郜黎蓟薄印宿白怀蒲邰从鄂索咸籍赖卓蔺屠蒙池乔阴郁胥能苍双闻莘党翟谭贡劳逄姬申扶堵冉宰郦雍隙璩桑桂濮牛寿通` +
		`边扈燕冀郏浦尚农温别庄晏柴瞿阎充慕连茹习宦艾鱼容向古易慎戈廖庾终暨居衡步都耿满弘匡文国寇广禄阙东欧殳沃利蔚越夔隆师巩厍聂晁勾敖融` +
		`冷訾辛阚那简饶空曾毋沙乜养鞠须丰巢关蒯相查后荆红游竺权逯盖益桓公`
	twoWords := `万俟,司马,上官,欧阳,夏侯,诸葛,闻人,东方,赫连,皇甫,尉迟,公羊,澹台,公冶,宗政,濮阳,淳于,单于,太叔,` +
		`申屠,公孙,仲孙,轩辕,令狐,锺离,宇文,长孙,慕容,鲜于,闾丘,司徒,司空,亓官,司寇,子车,颛孙,端木,` +
		`巫马,公西,漆雕,乐正,壤驷,公良,拓跋,夹谷,宰父,穀梁,段干,百里,东郭,南门,呼延,羊舌,微生,梁丘,左丘,东门,西门,南宫,第五`
	twoFamily := strings.Split(twoWords, ",")
	oneFamily := strings.Split(oneWord, "")
	familyNames := append(oneFamily, twoFamily...)
	getNum := GetRandNum(0, len(familyNames)-1) // 最大是
	return familyNames[getNum]
}

// GetRandChineseName 随机生成姓名
func GetRandChineseName() string {
	first := GetRandFamilyName()
	last := GetRandName(GetRandNum(1, 2), true)

	return fmt.Sprintf("%s%s", first, last)
}

// RemovePrefix 去掉字符串前缀
func RemovePrefix(str, prefix string) string {
	if strings.HasPrefix(str, prefix) {
		return strings.TrimPrefix(str, prefix)
	}
	return str
}

// RandUuid 生成随机ID
func RandUuid() string {
	return uuid.New().String()
}
